﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class DocPatient : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Card = Request.QueryString["IDCard"];
            string sql = string.Format("select * from Hospitalizat INNER JOIN Patient ON Hospitalizat.PatIDCard = Patient.IDCard where IDCard='{0}'", Card);
            SqlDataReader dr = DBHelper.GetDataReader(sql);
            while (dr.Read())
            {
                LblName.Text = dr["Name"].ToString();
                LblPhone.Text = dr["Phone"].ToString();
                LblSex.Text = dr["Sex"].ToString();
                LblAge.Text = dr["Age"].ToString();
                LblSymptom.Text = dr["Symptom"].ToString();
                LblDiagnosis.Text = dr["Diagnosis"].ToString();
                TxtOrder.Text = dr["DocOrder"].ToString();
            }
            LblIDCard.Text = Card;
            dr.Close();
        }
    }

    string Name = "";
    protected void TxtName_TextChanged(object sender, EventArgs e)
    {
        string sql = string.Format("select * from DrugDict where ComName like'%{0}%'", TxtName.Text);
        SqlDataReader dr = DBHelper.GetDataReader(sql);

        while (dr.Read())
        {
            LblSpec.Text = dr["Spec"].ToString();
            LblPrice.Text = dr["Priceinfo"].ToString();
            Name = dr["ComName"].ToString();
        }
        dr.Close();
        TxtName.Text = Name;
    }

    protected void BtnYY_Click(object sender, EventArgs e)
    {
        if (TxtName.Text == "" && TxtDosage.Text == "" && TxtQuantity.Text == "")
        {
            Response.Write("<script> alert('药品添加失败，信息不能为空!') </script>");
        }
        else
        {
            string Doc = Session["Name"].ToString();
            string insertsql = string.Format("insert into Bill (DocID,IDCard,ComName,Specifications,Consumption,Quantity,Price) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", Doc, LblIDCard.Text, TxtName.Text, LblSpec.Text, TxtDosage.Text, TxtQuantity.Text, LblPrice.Text);
            DBHelper.GetNonQuery(insertsql);
            Response.Write("<script> alert('药品添加成功!') </script>");
            LblSpec.Text = "";
            TxtName.Text = "";
            TxtDosage.Text = "";
            TxtQuantity.Text = "";
            LblPrice.Text = "";
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("SelectDrugs.aspx");
    }

    protected void BtnTjCf_Click(object sender, EventArgs e)
    {
        string Card = Request.QueryString["IDCard"];
        string updatesql = string.Format("update Hospitalizat set DocOrder='{0}' where PatIDCard='{1}'", TxtOrder.Text, Card);
        DBHelper.GetNonQuery(updatesql);
        Response.Write("<script>alert('保存成功！')</script>");

    }

    protected void BtnCY_Click(object sender, EventArgs e)
    {
        string Card = Request.QueryString["IDCard"];
        string Date = DateTime.Now.ToString();
        string updatesql = string.Format("update Hospitalizat set LeaveTime='{0}',State='已出院' where PatIDCard='{1}'", Date, Card);
        DBHelper.GetNonQuery(updatesql);
        Response.Write("<script>window.location.href='Advice.aspx';</script>");
    }
}